package ɱɱɱ;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Scanner;

public class _04_birthday {

	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String [] info = new String[2*n];
		for(int i=0;i<2*n;i++){
			info[i] = in.next();
		}
		int temp = 0;
		int minyear = 1000;
		int maxyear = 0;
		int g = 0;
		int h = 0;
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy/mm/dd");
		String nowDate = formatter.format(calendar.getTime());
		for(int i = 1;i<2*n;i=i+2){
			if(prebath(info[i],nowDate)&&cyear(info[i],nowDate)<200){
				temp=temp+1;
				if(minyear>=cyear(info[i],nowDate)){
					minyear=cyear(info[i],nowDate);
					g = i;
				}
				if(maxyear<=cyear(info[i],nowDate)){
					maxyear=cyear(info[i],nowDate);
					h = i;
				}
			}
		}
		System.out.println(temp+" "+info[h-1]+" "+info[g-1]);
	}
	public static boolean prebath(String info,String nowDate){
		String[] s = info.split("/");
		String[] e = nowDate.split("/");
		
			if(Integer.parseInt(s[0])>Integer.parseInt(e[0])){
				return false;
			}else if((Integer.parseInt(s[0])==Integer.parseInt(e[0]))&&Integer.parseInt(s[1])>Integer.parseInt(e[1])){
				return false;
			}else if((Integer.parseInt(s[0])==Integer.parseInt(e[0]))&&(Integer.parseInt(s[1])==Integer.parseInt(e[1]))&&Integer.parseInt(s[2])>Integer.parseInt(e[2])){
				return false;
			}else{
				return true;
			}
	}
	
	public static int cyear(String info,String nowDate){
		String[] s = info.split("/");
		String[] e = nowDate.split("/");
		int year = 0;
		year = Integer.parseInt(e[0]) - Integer.parseInt(s[0]);//  2022/6/6    1822/7/6
		if(Integer.parseInt(s[1])>Integer.parseInt(e[1])){
			year--;
		}
		
		return year;
	}
}
